package com.framework.core.utils;

import org.springframework.util.StringUtils;

import java.nio.charset.Charset;

/**
 * @author 樊猛 [986314249@qq.com]
 * @create 2018/6/5 9:26
 */
public class PhoneUtil {

    /**
     * 判断是否有效号码
     * @param phone
     * @return
     */
    public static boolean isLegalPhoneNumber(String phone){
        if(StringUtils.isEmpty(phone) || phone.length() !=11){
            return false;
        }
        byte[] phoneBytes = phone.getBytes(Charset.forName("UTF-8"));
        for(byte b : phoneBytes){
            if(b < 0x30 || b > 0x39){
                return false;
            }
        }

        return true;
    }
}
